#include <bits/stdc++.h>
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;

const int N = 1e6 + 5;

void Solve() {
    string p, s;
    cin >> p;
    cin >> s;
    vector<pair<char, int>> vp;
    vector<pair<char, int>> vs;
    int indexp = 0;
    int indexs = 0;
    int m = 1, n = 1;
    vp.push_back({p[0], m});
    vs.push_back({s[0], n});
    for (int i = 1; i < p.length(); i++) {
        if (p[i] == p[i - 1]) {
            m++;
            vp.back().second = m;
        }
        else {
            m = 1;
            vp.push_back({p[i], m});
            indexp++;
        }
    }
    for (int i = 1; i < s.length(); i++) {
        if (s[i] == s[i - 1]) {
            n++;
            vs.back().second = n;
        }
        else {
            n = 1;
            vs.push_back({s[i], n});
            indexs++;
        }
    }
    indexp = 0;
    indexs = 0;
    while (indexp < vp.size() && indexs < vs.size()) {
        if (vp[indexp].first == vs[indexs].first) {
            int left = vs[indexs].second - vp[indexp].second;
            while (left > 0 && indexs + 1 < vs.size() && vs[indexs + 1].first == vs[indexs].first) {
                indexs++;
                left -= vs[indexs].second;
            }
            if (left < 0) {
                cout << "NO" << endl;
                return;
            }
            indexp++;
            indexs++;
        }
        else {
            cout << "NO" << endl;
            return;
        }
    }
    if (indexp == vp.size() && indexs == vs.size()) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--) Solve();

    return 0;
}